<template>
  <div class="activity-panel van-hairline--surround">
    <div class="activity-panel__cover">
      <img :src="data.thumb">
    </div>
    <div class="activity-panel__header">
      <div class="activity-panel__header-date">
        <h2 class="font-number">{{data.date.mark1}}</h2>
        <p>{{data.date.mark2}}</p>
      </div>
      <div class="activity-panel__header-title">
        <h2>{{data.name}}</h2>
        <p class="ellipsis-2">{{data.description}}</p>
      </div>
      <div class="activity-panel__header-status"></div>
    </div>
    <div class="activity-panel__footer van-hairline--top">
      <div class="activity-panel__avatars">
        <span v-for="user in data.recommends" :key="user.id">
          <img :src="user.avatar">
        </span>
      </div>
      <div class="activity-panel__tips">
        <span class="font-primary">{{data.partnerCount}}</span>
        <span>人参与</span>
      </div>
      <van-button type="danger" round plain size="small" @click="onView">{{data.viewText}}</van-button>
    </div>
  </div>
</template>
<script>
import { Icon, Cell, Button, Panel } from 'vant'
export default {
  components: {
    [Icon.name]: Icon,
    [Cell.name]: Cell,
    [Button.name]: Button,
    [Panel.name]: Panel
  },
  name: 'activity-cell',
  props: {
    data: Object,
    tpl: String
  },
  data () {
    return {
      active: false
    }
  },
  computed: {
    format () {
      if (this.tpl) {
        return this.tpl
      }
      return this.data.format
    },
    className () {
      return 'activity-cell__' + this.format
    },
    stats () {
      let stats = []
      stats.push(this.data.category.name)
      stats.push(this.data.publishTime)
      return stats.join(' | ')
    },
    label () {
      if (this.format === 'default') {
        return this.stats
      }
      return ''
    },
    babelTips () {
      if (this.data.format === 'gallery' && this.data.picture_nums > 0) {
        return this.data.picture_nums + '图'
      } else if (this.data.format === 'video' && this.data.duration) {
        return this.data.duration
      }
      return false
    },
    thumb () {
      let albums = this.data.pictures
      if (albums.length > 0 && albums.length < 3) {
        return albums.shift()
      }
      return false
    },
    link () {
      return this.data.link
    }
  },
  methods: {
    onView () {
      console.log(this.link)
      this.pushNativelink(this.link)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
@import "../../assets/less/functions.less";

.activity-panel {
  position: relative;
  padding: 100px 10px 10px;
  &::after {
    border-radius: 10px;
  }
  &__cover {
    position: absolute;
    left: 0;
    top: 0;
    height: 100px;
    overflow: hidden;
    &::before {
      position: absolute;
      left: 0;
      bottom: 0;
      content: "";
      width: 100%;
      height: 100%;
      .gradient3(transparent, transparent, white);
    }
    img {
      border-radius: 5px 5px 0 0;
      width: 100%;
    }
  }
  &__avatars {
    padding-right: 15px;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    flex-direction: row-reverse;
    span {
      display: inline-block;
      width: 15px;
      img {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        border: 1px solid #ccc;
      }
    }
    &:empty {
      padding-right: 0;
    }
  }
  &__tips {
    flex: 1;
  }

  &__header,
  &__footer {
    -moz-box-align: center;
    -moz-box-pack: justify;
    align-items: center;
    align-content: space-around;
    box-sizing: border-box;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    justify-content: center;
    overflow: hidden;
    flex-wrap: nowrap;
    width: 100%;
    position: relative;
  }
  &__header {
    padding: 10px 0 5px;
    &-date {
      flex: 0 1 auto;
      width: 44px;
      padding-right: 10px;
      text-align: center;
      > * {
        margin: 0;
      }
      h2 {
        font-size: 20px;
        font-weight: bold;
      }
      p {
        font-size: 10px;
        margin-top: 10px;
      }
    }
    &-title {
      flex: 1;
      > * {
        margin: 0;
      }
      h2 {
        font-size: 16px;
        line-height: 24px;
      }
      p {
        font-size: 10px;
        margin-top: 3px;
        color: #aaa;
        font-weight: 300;
        line-height: 18px;
      }
    }
    &-status {
    }
  }
  &__footer {
    padding-top: 10px;
  }
}
</style>
